var server = require('../../../utils/server');
Page({
	data: {
		orderId: '',
		formId:'',
	},
	onLoad: function (options) {
		var orderId = options.order_id;
		var app = getApp();
		var order = app.globalData.order;
		var wxdata = app.globalData.wxdata

		this.setData({
			order: order,
      orderId: orderId,
			wxdata:wxdata
		})
	},

	pay: function (e) {
		var formId = e.detail.formId;

		var app = getApp();
		var wxdata = app.globalData.wxdata.wdata;
		var timeStamp = wxdata.timeStamp + "";
		var nonceStr = wxdata.nonceStr + "";
		var package1 = wxdata.package
		var sign = wxdata.sign;
   		var orderSn = app.globalData.order.order_sn;
    // var orderId = this.data.order_id;

    var that =this;

			 wx.requestPayment({
			    
			  'nonceStr': nonceStr,
		      'package': package1,
         // 'package': 'prepay_id='+package1,
			    'signType': 'MD5',
				 'timeStamp': timeStamp,
			    'paySign': sign,
			    'success':function(res){

					wx.showToast({
		              title: '支付成功',
		              icon: 'success',
		              duration: 2000
		            });	
		             var order_id = that.data.orderId;
		          


		            // console.log(order_id);
		            //     console.log(formId); return
		             server.getJSON('/Cart/update_pay_status/formId/'+formId+'/order_id/' +order_id,function(res){});
		            
			    	setTimeout(function () {
		                wx.switchTab({
		                url: "../../member/index/index"
				        });
				      }, 2000);
			    },
			    'fail':function(res){
			    		wx.showToast({
			  title: '支付失败',
			  icon: 'success',
			  duration: 2000
			})
			    }
			 })

			
	}
})